﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.AppService.Dto;
using TR.AppService.Dto.RKGLDto;
using TR.Domain.Entity.CKGL;
using TR.Domain.Repository.CKGLRepository;

namespace TR.AppService.AppService.CKGL
{
    public class wh_Outbill_hAppService : Iwh_Outbill_hAppService
    {
        private readonly IMapper mapper;
        private readonly Iwh_Outbill_hRepository iwoh;

        public wh_Outbill_hAppService(IMapper mapper,Iwh_Outbill_hRepository iwoh)
        {
            this.mapper = mapper;
            this.iwoh = iwoh;
        }
        //出库管理新增
        public async Task<bool> CKGLInsert(CKGLJcxx jcxx, List<CKGLCkmx> ckmx)
        {
            wh_Outbill_h woh = mapper.Map<wh_Outbill_h>(jcxx);
            var wod = mapper.Map<List<wh_Outbill_d>>(ckmx);
            return await iwoh.CKGLInsert(woh, wod);
        }

        //出库关联单号
        public async Task<DtoFenYe<CKDHGuanlian>> CKGuanlian(int mys, int dqy, string? dqsj, string? jssj, CKGLDHTjDto tj)
        {
            var listFenye = await iwoh.CKGLGuanlian(mys, dqy, dqsj, jssj, tj);
            var glzts = await iwoh.Ztshu();
            var result = new DtoFenYe<CKDHGuanlian>()
            {
                mys = mys,
                dqy = dqy,
                list = listFenye,
                zts = glzts,
            };
            return result;
        }

        //根据销售单号查询对应商品
        public async Task<List<XSDHchaHP>> XSDHChahp(string sale_code, HPTj tj)
        {
            return await iwoh.XSDHChahp(sale_code, tj);
        }

        //出库管理订单主表查询
        public async Task<DtoFenYe<CKGL_SelectZB>> CKGLSelect(int mys, int dqy, CKGLZbTjCx tj)
        {
            var listFenye = await iwoh.CKGLZBSelect(mys, dqy, tj);
            var zbzts = await iwoh.ZbZts();
            var result = new DtoFenYe<CKGL_SelectZB>()
            {
                mys = mys,
                dqy = dqy,
                list = listFenye,
                zts = zbzts,
            };
            return result;
        }

        //批量删除
        public async Task<bool> CKGLDelete(List<int> isdel)
        {
            return await iwoh.CKGLDelete(isdel);
        }
    }
}
